ROOTDIR=$(shell pwd)/../..
SRC_DIR= $(ROOTDIR)/src
OBJ_DIR=$(ROOTDIR)/obj
BIN_DIR=$(ROOTDIR)/bin
LIB_DIR=$(ROOTDIR)/lib
INC_DIR=$(ROOTDIR)/inc

CC=gcc
AR=ar
CFLAGS=-W -Wall -O2 -DNDEBUG
LDFLAGS=

CFLAGS_D=$(CFLAGS:-DNDEBUG=-DDEBUG) -ggdb3
LDFLAGS_D=$(LDFLAGS) -ggdb3

all : List.a List_d.a install run

%.a : %.o
	@echo ==== linking $@ ====
	@$(AR) rc $@ $< $(LDFLAGS)

testList: testList_d.o List_d.o
	@echo "==== compiling test (Debug) $@ ===="
	@$(CC) -o $@ $^ $(LDFLAGS_D)

%.o : %.c
	@echo ==== compiling $@ ====
	@$(CC) -c -o $@ $< $(CFLAGS)

%_d.o : %.c
	@echo "==== compiling (Debug) $@ ===="
	@$(CC) -c -o $@ $< $(CFLAGS_D) 



.PHONY = clean install run

install :
	@echo ==== Installing Library ====
	@cp List.a $(LIB_DIR)/libList.a 2> /dev/null
	@cp List_d.a $(LIB_DIR)/libList_d.a 2> /dev/null
	@cp List.h $(INC_DIR)/List.h 2> /dev/null
	@cp testList $(BIN_DIR)/test/ 2> /dev/null

clean :
	@echo ==== Cleaning ====
	@rm -rf *.o *.a testList
	
run :
	@echo ==== Running Test App ====
	@./testList > /dev/null
	@echo ==== Test Run ====
